<?php

/***@property string $source_database
*@property string $last_run
*@property string $node_name
 */

namespace backend\modules\tool\models;

use backend\modules\tool\DataSource\Log\Log;
use backend\modules\tool\DataSource\Log\PidRecord;
use backend\modules\tool\Job\DataBaseBackNode;

class DataBaseBack extends \backend\modules\tool\models\BaseModel
{
    /**
     * @inheritdoc
     */
    protected static $create_sql="create table t_databaseback_back_fill(id int(11) not null primary key auto_increment comment 'id',source_database varchar(50) default null comment '目标节点库',last_run varchar(50) default null comment '上次执行时间',node_name varchar(50) default null comment '节点名称',updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    public static function tableName()
    {
        return '{{%t_databaseback_back_fill}}';
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['source_database','last_run','node_name'],'string','max'=>'50']
        ];
    }
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'source_database'=>'目标节点库',
            'last_run'=>'上次执行时间',
            'node_name'=>'节点名称',
                    ];
    }

    /**
     * @param $id
     * @return PidRecord
     */
    public static function getPidRecord($id){
        return PidRecord::SingleTon(self::getName($id));
    }
    public static function getLog($id){
        return Log::SingleTon(self::getName($id));
    }
    public static function getName($id){
        $class_path=str_replace("\\","_",DataBaseBackNode::class);
        return $id.$class_path;
    }
}